package com.server.rule.component.triple.complex;


import java.util.List;

import org.jdom.Element;

import com.server.rule.component.triple.Triple;
import com.server.rule.component.triple.simple.BooleanTriple;
import com.server.rule.component.triple.simple.NominalTriple;
import com.server.rule.component.triple.simple.NumericTriple;
import com.server.rule.data.Data;
import com.server.rule.data.ExceptionTypeData;

public class ComplementTriple extends Triple{

	private Triple baseTriple;
	
	//@Override
	public boolean equals(Triple p) {
		if(!(p instanceof ComplementTriple)) return false;
		return baseTriple.equals(((ComplementTriple) p).baseTriple);
	}
	
	
	
	public void generateFromXML(Element xmlElement) {	
		
		if(xmlElement.getChild("Triple").getAttributeValue("type").equals("NominalTriple")) baseTriple = new NominalTriple();
		if(xmlElement.getChild("Triple").getAttributeValue("type").equals("NumericTriple")) baseTriple = new NumericTriple();
		if(xmlElement.getChild("Triple").getAttributeValue("type").equals("BooleanTriple")) baseTriple = new BooleanTriple();
		if(xmlElement.getChild("Triple").getAttributeValue("type").equals("AndTriple")) baseTriple = new AndTriple();
		if(xmlElement.getChild("Triple").getAttributeValue("type").equals("OrTriple")) baseTriple = new OrTriple();
		if(xmlElement.getChild("Triple").getAttributeValue("type").equals("ComplementTriple")) baseTriple = new ComplementTriple();
		baseTriple.generateFromXML(xmlElement.getChild("Triple"));
	}

	
	public Element getXMLElement() {
		Element xmlElement = new Element("Triple");
		
		xmlElement.setAttribute("type","ComplementTriple");
		xmlElement.addContent(baseTriple.getXMLElement());		
		return xmlElement;
	}
	
	//@Override
	public boolean match(Data data) throws ExceptionTypeData {
		return !baseTriple.match(data);
	}

	/**
	 * @param baseTriple the baseTriple to set
	 */
	public void setBaseTriple(Triple baseTriple) {
		this.baseTriple = baseTriple;
	}

	/**
	 * @return the baseTriple
	 */
	public Triple getBaseTriple() {
		return baseTriple;
	}

	
	public String getHumanReadable() {
		return "NOT("+baseTriple.getHumanReadable()+")";
	}

	@Override
	public void getUsedVar(List<String> listeUsedVar) {
		baseTriple.getUsedVar(listeUsedVar);		
	}

}
